package DBConnection;

import com.trade.domain.ItemSellDo;
import com.trade.utils.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.Date;

/**
 * Created by Administrator on 2016/10/15.
 */
public class Client {
    public static void main(String[] args) {

        Session session = null;
        try{
            session = HibernateUtil.getSession();
            //开启事务
            session.beginTransaction();

            ItemSellDo itemSellDo = new ItemSellDo();
            itemSellDo.setCommodityDesc("sss");
            itemSellDo.setCommodityImage("sdgfg");
            itemSellDo.setCommodityName("sdfdg");
            itemSellDo.setCommodityType("dggr");
            itemSellDo.setPrice(12);
            itemSellDo.setScore("sdgfg");
            itemSellDo.setSellerId(12);
            itemSellDo.setSellerNickName("dsgrg");
            itemSellDo.setSellerQQ("824111934");
            itemSellDo.setStatus(1);
            itemSellDo.setUploadTime(new Date());
            session.save(itemSellDo);
            //提交事务
            session.getTransaction().commit();

        }catch(Exception e){
            e.printStackTrace();
            //回滚事务
            session.getTransaction().rollback();
        }finally{
            if(session != null){
                if(session.isOpen()){
                    //关闭session
                    session.close();
                }
            }
        }
    }
}
